package com.ketai.dao.impl;

import java.util.Date;

import com.ketai.dao.BaseDao;
import com.ketai.dao.StyleDao;
import com.ketai.vo.StyleVo;

import javax.naming.NamingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:长沙科泰梦想学院-蓝色小药丸
 * @Mission:打造演说·创客型跨境电商与互联网人才
 * @Description:
 * @Date:Create In 2022/8/10 23:06
 **/
public class StyleDaoImpl extends BaseDao implements StyleDao {
    @Override
    public int saveImageUrls (Object[] params) throws SQLException, NamingException {
        String sql = "insert style (id, a_id,paths,uid) values(null,?,?,?)";
        return curdMethod(sql, params);

    }

    @Override
    public List<StyleVo> getStyleList (String sql, Object[] params) throws SQLException, NamingException {

        ResultSet rs = query(sql, params);
        List<StyleVo> styleVoItem = new ArrayList<StyleVo>();
        while (rs.next()) {
            StyleVo vo = new StyleVo();
            vo.setId(rs.getInt("id"));
            vo.setTitle(rs.getString("title"));
            vo.setPaths(rs.getString("paths"));
            vo.setCreateTime(rs.getDate("createTime"));
            vo.setuName(rs.getString("nickName"));
            vo.setChecked(rs.getInt("checked"));
            vo.setCheckedName(rs.getString("checkedName"));
            vo.setCheckedTime(rs.getDate("checkedTime"));
            vo.setoName(rs.getString("oName"));
            vo.setTypeName(rs.getString("typeName"));
            styleVoItem.add(vo);
        }

        return styleVoItem;
    }

    @Override
    public long getStyleCount (String sql, Object[] toArray) throws SQLException, NamingException {
        Long total = 0L;
        ResultSet rs = query(sql, toArray);
        while (rs.next()) {
            total = rs.getLong("total");
        }
        return total;
    }

    @Override
    public int checkedActity (String sql, Object[] params) throws SQLException, NamingException {
        int i = curdMethod(sql, params);
        return i;

    }
}
